<?php
    include_once("../service/categoryService.php");
    include_once("../service/productService.php");
    
    $catID = $_POST['checkbox'];
    $catIDs = count($_POST['checkbox']);

    if(!isset($catID) || !isset($catIDs)){
        echo "<script>window.location = '../admin-page/category.php'</script>";
    }

    for($i = 0; $i < $catIDs; $i++){
        $delID = $catID[$i];
        // cannot delete categroies haing products
        $numProducts = getNumProductsByCategory($delID);
        if($numProducts[0] > 0){
            echo "<script>window.location = '../admin-page/category.php?actionResult=cannot'</script>";
        } else {
            $actionResult = deleteCategory($delID);
        }
    }

    if($actionResult)
        echo "<script>window.location = '../admin-page/category.php?actionResult=ok'</script>";
    else
        echo "<script>window.location = '../admin-page/category.php?actionResult=no'</script>";
?>